home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
MCASM.RAR
/
MC_ASM.EXE
/
WROX_ASM
/
CH12
/
COMMON
/
KEYMOUSE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-24
|
3KB
|
168 lines
/************************************************************************/
/* This program is implementation of */
/* mouse & keyboard dealing procedure described in keymouse.h */
/* Kiselev Y. & E.Podvoysky from ^Z for WROX press book, 1994 */
/************************************************************************/
#include <dos.h>
#include <conio.h>
#include "graph.h"
#include "keymouse.h"
WORD readkeyword() {
asm {
xor ax,ax
int 16h
}
}
BYTE keyboardstatus() {
asm {
mov ah,2
int 16h
}
}
/////////////////////////////////////////////////////////////////
int num_of_buttom;
int mousex,mousey,oldx,oldy;
BOOL visible_mouse = FALSE;
WORD buttons = 0;
BYTE ppb = 3; // 0 for 640x480x16,320x200x256
// 3 for 640x480x256,800x600x256
BYTE getmousedata(int &x,int &y) {
asm {
mov ax,3;
int 0x33;
}
x = _CX; y = _DX;
x >>= ppb;
y >>= ppb;
return(_BX);
}
int initmouse() {
asm { xor ax,ax; int 0x33;}
if (_AX == 0xFFFF) {num_of_buttom = _BX; return 0;} else return -1;
}
void hide_mouse() {
asm { mov ax,2; int 0x33;}
}
void show_mouse() {
asm { mov ax,1; int 0x33;}
}
void hide_mymouse() {
if (visible_mouse) {
setwritemode(XOR_PUT);
setcolor(255);
line(oldx - 10,oldy,oldx + 10, oldy);
line(oldx ,oldy - 10,oldx,oldy + 10);
setwritemode(NORMAL_PUT);
}
visible_mouse = FALSE;
}
void show_mymouse() {
if (!visible_mouse) {
setwritemode(XOR_PUT);
setcolor(255);
line(mousex - 10,mousey,mousex + 10, mousey);
line(mousex ,mousey - 10,mousex,mousey + 10);
oldx = mousex; oldy = mousey;
setwritemode(NORMAL_PUT);
}
visible_mouse = TRUE;
}
void move_mymouse() {
if ((mousex != oldx) || (mousey != oldy)) { hide_mymouse(); show_mymouse();}
}
void setmousepos(int x,int y) {
mousex = x; mousey = y;
x <<= ppb;
y <<= ppb;
asm {
mov ax,4;
mov cx,x;
mov dx,y;
int 0x33
}
}
void setmouserange(int x1,int y1,int x2,int y2) {
x1 <<= ppb;
x2 <<= ppb;
y1 <<= ppb;
y2 <<= ppb;
asm {
mov ax,7;
mov cx,x2;
mov dx,x1;
int 0x33;
mov ax,8;
mov cx,y2;
mov dx,y1;
int 0x33;
}
}
void setmousehandler(void far *handle,WORD mask) {
asm {mov ax,12; les dx,handle; mov cx,mask; int 0x33}
}
void far mousehandler() {
asm {
push ds
mov ax,SEG mousex
mov ds,ax
mov ax,cx
mov cl,ppb
shr ax,cl
mov mousex,ax
mov ax,dx
shr ax,cl
mov mousey,ax
mov bh,0
mov buttons,bx
pop ds
}
}
void initmouse_easy() {
initmouse();
setmousehandler(mousehandler,0x007F);
}
void getmousestate(int &x,int &y,WORD &button) {
int i;
button = buttons;
while (buttons >= button) {
move_mymouse();
button = buttons;
for(i=0;i<50;i++);
}
while (buttons != 0) for(i=0;i<50;i++);
x = mousex;
y = mousey;
}
void delay_key(long time) {
for (; time > 0; time--) {
delay(1);
if (kbhit()) break;
}
}
void clearkey() { while (kbhit()) readkeyword();}
void delay_key1(long time) {
clearkey();
delay_key(time);
}